package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.RedPacMapper;
import com.gxa.p2p.pojo.Redpac;
import com.gxa.p2p.pojo.Redpaclog;
import com.gxa.p2p.service.RedPacService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

/**
 * @author R
 * @data 2021-10-26 16:14
 */
@Service
public class RedPacServiceImpl implements RedPacService {

    @Autowired
    RedPacMapper redPacMapper = null;

    @Override
    public void addRedPac(Redpac redpac) {
        redpac.setColNum(0);
        redpac.setUseNum(0);
        redpac.setCreatTime(new Timestamp(System.currentTimeMillis()));
        if (redpac.getExpTime().equals("0")){
            redpac.setExpTime("-");
        }
        redPacMapper.addRedPac(redpac);
    }

    @Override
    public List<Redpac> findRedPac(String name, String type, Integer page, Integer size) {
        if (page == null){
            List<Redpac> redPac = redPacMapper.findRedPac(name, null, null, null);
            return redPac;
        }else {
            List<Redpac> redPac = redPacMapper.findRedPac(name, type, (page - 1) * size, size);
            return redPac;
        }

    }

    @Override
    public Integer findRedPacCount(String name, String type, Integer page, Integer size) {
        page = null;
        size = null;
        List<Redpac> redPac = redPacMapper.findRedPac(name, type, page, size);
        return redPac.size();
    }

    @Override
    public List<Redpaclog> findRedPacLogByPage(String invPhone, String invName, String name, String userOrigin, String colType, String state, Integer page, Integer size) {
        List<Redpaclog> redPacLogByPage = redPacMapper.findRedPacLogByPage(invPhone, invName, name, userOrigin, colType, state, (page - 1) * size, size);

        return redPacLogByPage;
    }

    @Override
    public List<Redpaclog> findRedPacLogNoPage(String invPhone, String invName, String name, String userOrigin, String colType, String state, Integer page, Integer size) {
        List<Redpaclog> redPacLogByPage = redPacMapper.findRedPacLogByPage(invPhone, invName, name, userOrigin, colType, state, null, null);

        return redPacLogByPage;
    }

    @Override
    public Integer findRedPacLogCount(String invPhone, String invName, String name, String userOrigin, String colType, String state, Integer page, Integer size) {
        page = null;
        size = null;
        List<Redpaclog> redPacLogByPage = redPacMapper.findRedPacLogByPage(invPhone, invName, name, userOrigin, colType, state, page, size);

        return redPacLogByPage.size();
    }
}
